package com.zth.controller;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.zth.pojo.Link;
import com.zth.service.LinkService;

@RestController
@RequestMapping("link")
public class LinkController {
	@Autowired
	private LinkService linkService;
	
	@RequestMapping("linkAll")
	public Map<String, Object> linkAll(@RequestParam(defaultValue = "1",name = "page")int page,@RequestParam(defaultValue = "10",name = "limit") int pageSize){
		List<Link> list=linkService.linkAll(page,pageSize);
		PageInfo<Link> info=new PageInfo<>(list);
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("message", "");
		map.put("code", 0);
		map.put("count", info.getTotal());
		map.put("data", info.getList());
		return map;
	}
	
	@RequestMapping("add")
	public int add(Link link) {
		link.setCreate_time(LocalDateTime.now());
		return linkService.add(link);
	}
	
	@RequestMapping("linkById")
	public Link linkById(int link_id) {
		return linkService.linkById(link_id);
	}
	
	@RequestMapping("edit")
	public int edit(Link link) {
	return	linkService.edit(link);
	}
	
	@RequestMapping("deleteBatch")
	public int deleteBatch(@RequestParam(name = "ids[]") int[] ids) {
		
		return linkService.deleteBatch(ids);
	}
}
